package com.csii.branch.activity.server.impl;

import com.csii.activiti.server.abstraction.entity.ActRole;
import com.csii.activiti.server.abstraction.service.ActRoleService;
import com.csii.core.api.Result;
import com.csii.user.entity.SysRole;
import com.csii.user.service.ISysUserBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@Service
public class ActRoleServiceImpl implements ActRoleService {

    @Autowired
    private ISysUserBaseService sysUserBaseService;

    @Override
    public List<ActRole> queryRoleLikeRoleName(String roleName) {
        Result<List<SysRole>> listResult = sysUserBaseService.queryRoleLikeRoleName(roleName);
        if (listResult != null){
            List<SysRole> result = listResult.getResult();
            return result.stream().map(item-> new ActRole(item.getRoleName(),item.getRoleCode())).collect(Collectors.toList());
        }
        return new ArrayList<>();
    }

    @Override
    public List<ActRole> queryRoleByRoleCodes(Set<String> roleCodes) {
        Result<List<SysRole>> listResult = sysUserBaseService.queryRoleByRoleCodes(new ArrayList<>(roleCodes));
        if (listResult != null){
            List<SysRole> result = listResult.getResult();
            return result.stream().map(item-> new ActRole(item.getRoleName(),item.getRoleCode())).collect(Collectors.toList());
        }
        return new ArrayList<>();
    }
}
